package com.soft.cake.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.soft.cake.mapper.ProductMapper;
import com.soft.cake.pojo.Product;
import com.soft.cake.service.IProductService;

@Service
public class ProductServiceImpl implements IProductService {

	@Autowired
	private ProductMapper productMapper;
	
	/**
	 * @author Yanyan Shi
	 * @description 通过商品id获得商品信息
	 * @param productId
	 * @param Product
	 */
	@Override
	public Product detailsProduct(Integer productId) {
		// TODO Auto-generated method stub
		Product product = productMapper.selectByPrimaryKey(productId);
		if (product==null) {
			return null;
		}
		return product;
	}
	/**
	 * @author Qijuan Liu
	 * @description 通过商品id获得全部商品信息
	 * @param productId
	 * @param Product
	 */
	public List<Product> listProducts(List<Integer> productIds){
		List<Product> products=productMapper.selectProducts(productIds);
		if(products == null)
			// TODO Auto-generated method stub
				return null;
			else
				return products;
	}
	
	/**
	 * @author Huo Sa
	 * @description 获得全部商品信息
	 * @param productId
	 * @param Product
	 */
	@Override
	public List<Product> listProducts() {
		List<Product> products = productMapper.selectAllProducts();
		if(products == null)
		// TODO Auto-generated method stub
			return null;
		else
			return products;
	}
	/**
	 * @author Huo Sa
	 * @description 通过商品id获得商品信息
	 * @param productId
	 * @param Product
	 */
	@Override
	public Product oneProduct(Integer productId) {
		Product product = productMapper.selectByPrimaryKey(productId);
		if(product == null)
			// TODO Auto-generated method stub
				return null;
			else
				return product;
	}
	/**
	 * @author Qijuan Liu
	 * @description 获得全部商品信息by products
	 * @param productId
	 * @param Product
	 */
	@Override
	public List<Product> listProductsById(List<Product> products) {
		List<Product> products2 = new ArrayList<Product>();
		for(Product product : products) {
			product = productMapper.selectProductByProductId(product.getProductId());
			products2.add(product);
		}
		if(products == null)
		// TODO Auto-generated method stub
			return null;
		else
			return products;
	}
	
	/**
	 * 
	 * @author CanLig
	 * @date 2019年8月24日 下午3:24:09
	 * @version 1.0.0
	 * @description 获取某个商品的图片
	 * @TODO
	 */
	@Override
	public Product getProductImg(Integer productId) {
		return productMapper.selProductWithImgByProId(productId);
	}
	
	/** @author Huo Sa
	 * @description 查询前八条记录用于首页展示
	 */
	public List<Product> selectEightProducts() {
		List<Product> products = new ArrayList<Product>();
		products = productMapper.selectEightProducts();
		return products;
	}

}
